package my2Cents;

import java.util.Vector;

public class KeyValue {
	private String line;
	private String key;
	private String value;
	private String niceName;
	
	public KeyValue(String l) {
		line = l;
		String[] data = line.split("-",2);
		key = data[0];
		value = data[1];
		niceName = value;
	}
	
	public KeyValue(String key, String value) {
		this.key = key;
		this.value = value;
		niceName = value;
	}
	
	public KeyValue(String nice, String key, String value) {
		this.key = key;
		this.value = value;
		niceName = nice;
	}
	
	public KeyValue clone() {
		return new KeyValue(niceName,key,value);
	}
	
	public String getNiceName() {
		return niceName;
	}
	
	public void setKey(String k) {
		key = k;
	}
	
	public String key() {
		return key;
	}
	
	public void setValue(String v) {
		value = v;
	}
	
	public String value() {
		return value;
	}
	
	public String toString() {
		return key + " = " + value;
	}
	
	public static KeyValue FindByKey(String key, Vector<KeyValue> kvVector) {
		for(int i=0; i<kvVector.size(); i++) {
			KeyValue hl = kvVector.get(i);
			if(hl.key().equals(key)) {
				return hl;
			}
		}
		return new KeyValue(key,"");
	}
	
	public static KeyValue FindByValue(String value, Vector<KeyValue> kvVector) {
		for(int i=0; i<kvVector.size(); i++) {
			KeyValue hl = kvVector.get(i);
			if(hl.value().equals(value)) {
				return hl;
			}
		}
		return new KeyValue("",value);
	}
}
